﻿using System.CodeDom;
using System.Linq;
using Roslyn.Compilers.CSharp;

namespace WeaverCustomTool
{
    public struct NamespaceDeclaration
    {
        /// <summary>
        /// Creates a CodeNamespace from a syntax namespace.
        /// </summary>
        /// <param name="namespace">The namespace.</param>
        /// <returns></returns>
        public CodeNamespace FromNamespace(NamespaceDeclarationSyntax @namespace)
        {
            var weavedNamespace = new CodeNamespace()
            {
                Name = @namespace.Name.ToString()
            };

            // Import interface namespaces
            weavedNamespace.Imports.AddRange(
                @namespace.Usings
                .Select(p => new CodeNamespaceImport(p.Name.ToFullString().Trim())).ToArray());

            return weavedNamespace;
        }
    }
}
